import 'dart:io';
import 'package:flutter/material.dart';
import 'package:honeypotflutter/modules/autonym/help/autonym_help.dart';
import 'package:honeypotflutter/publicBussine/bussine_colors.dart';
import 'package:honeypotflutter/publicBussine/bussine_font.dart';
import 'package:honeypotflutter/publicBussine/bussine_image.dart';
import 'package:image_picker/image_picker.dart';

class AutonymItemImage extends StatelessWidget {
  final String title;
  final XFile? file;
  final String hintImage;
  final AutonymSelectImageType type;
  final Function(AutonymSelectImageType type)? onDelete;
  final Function(AutonymSelectImageType type)? onSelectImage;

  const AutonymItemImage({
    super.key,
    required this.title,
    this.file,
    required this.hintImage,
    this.onDelete,
    this.onSelectImage,
    this.type = AutonymSelectImageType.front,
  });

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        SizedBox(height: 20),
        Text(
          title,
          style: TextStyle(
            fontSize: MGFont.textFont2,
            color: MGColors.text2Color,
          ),
        ),
        SizedBox(height: 10),
        Stack(
          children: [
            InkWell(
              child: Container(
                width: double.infinity,
                child: (file != null) ? Image.file(File(file!.path)) : Image.asset(hintImage),
              ),
              onTap: () {
                if (onSelectImage != null) {
                  onSelectImage!(type);
                }
              },
            ),
            Container(
              child: (file != null)
                  ? InkWell(
                      child: Image.asset(
                        MGImage.image("autonym_delete.png", type: ImagePathType.autonym),
                        width: 30,
                      ),
                      onTap: () {
                        if (onDelete != null) {
                          onDelete!(type);
                        }
                      },
                    )
                  : Container(),
            )
          ],
          alignment: AlignmentDirectional.topEnd,
        )
      ],
      crossAxisAlignment: CrossAxisAlignment.start,
    );
  }
}
